<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // arr[Symbol.iterator]()
      const team = {
        name: "终极一班",
        members: ["xiaoming", "xiaoning", "xiaotian", "knight"],
        //声明一个下标
        index: 0,
        //声明 Symbol.iterator 方法
        [Symbol.iterator](){
          //保存 this
          let _this = this;
          //返回迭代器对象
          return {
            next(){
              //返回一个对象
              //判断是否结束了
              if(_this.index >= _this.members.length){
                return {
                  done: true,
                  value: undefined
                }
              }else{
                return {
                  done: false,
                  value: _this.members[_this.index++]
                }
              }
            }
          }
        }
      };

      //for...of 对 team 对象进行遍历
      for(let v of team){
        console.log(v);
      }
    </script>
  </body>
</html>
